package edu.fh.salzburg.its.opsystems.newfs.definition;

import java.util.EnumSet;


public enum FileAttributes {

	WRITEPROTECT, 
	HIDDEN,
	SYSTEMFILE,
	VOLUMELABEL,
	DIRECTORY,
	ARCHIV;
	
	public static int getValue(EnumSet<FileAttributes> set) {
		if (set.size() >= Integer.SIZE) {
			throw new IllegalArgumentException("the EnumSet contains more than 32 values.");
		}
		int value = 0;
		for(FileAttributes val : set) {
			value |= 1 << val.ordinal();
		}
		return value;
	}

	public static EnumSet<FileAttributes> getFromInt(int value) {
		EnumSet<FileAttributes> fattrib = EnumSet.noneOf(FileAttributes.class);
		for(FileAttributes fa : FileAttributes.values()) {
			if ((value & (1 << fa.ordinal())) != 0) {
				fattrib.add(fa);
			}
		}
		return fattrib;
	}
}
